package com.itheima;

import com.itheima.service.UserService;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class UserServiceApplication {
    public static void main(String[] args) throws IOException {
        //1. 创建一个服务器端socket
        ServerSocket ss = new ServerSocket(10001);
        //2. 定义一个线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                350,
                500,
                30,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );


        while (true) {
            //3. 监听客户端socket连接
            Socket socket = ss.accept();
            //4. 创建一个线程任务来处理当前socket的请求
            pool.submit(new UserService(socket));
        }

    }
}
